<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单位姓名" prop="departmentName">
        <el-input
          v-model="queryParams.departmentName"
          placeholder="请输入单位姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="creditCodes">
        <el-input
          v-model="queryParams.creditCodes"
          placeholder="请输入统一社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="监管JDS" prop="representativeOffice">
        <el-input
          v-model="queryParams.representativeOffice"
          placeholder="请输入监管JDS"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="菜单" prop="menus">
        <el-input
          v-model="queryParams.menus"
          placeholder="请输入菜单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="KJ主业务分公司地址" prop="forceMainAddress">
        <el-input
          v-model="queryParams.forceMainAddress"
          placeholder="请输入KJ主业务分公司地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机要地址" prop="confidentialAddress">
        <el-input
          v-model="queryParams.confidentialAddress"
          placeholder="请输入机要地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="属性" prop="properties">
        <el-input
          v-model="queryParams.properties"
          placeholder="请输入属性"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属管辖类别" prop="categoryOfJurisdiction">
        <el-input
          v-model="queryParams.categoryOfJurisdiction"
          placeholder="请输入所属管辖类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上市情况" prop="listedSituation">
        <el-input
          v-model="queryParams.listedSituation"
          placeholder="请输入上市情况"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="BM等级" prop="securityGrade">
        <el-input
          v-model="queryParams.securityGrade"
          placeholder="请输入BM等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="BM等级证书编号" prop="securityCertificateNo">
        <el-input
          v-model="queryParams.securityCertificateNo"
          placeholder="请输入BM等级证书编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承制资格" prop="grindersQualification">
        <el-input
          v-model="queryParams.grindersQualification"
          placeholder="请输入承制资格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承制资格证书编号" prop="grindersQualificationNo">
        <el-input
          v-model="queryParams.grindersQualificationNo"
          placeholder="请输入承制资格证书编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申办日期" prop="bidDate">
        <el-input
          v-model="queryParams.bidDate"
          placeholder="请输入申办日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="续申日期" prop="renewedDate">
        <el-input
          v-model="queryParams.renewedDate"
          placeholder="请输入续申日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到期日期" prop="dateDue">
        <el-input
          v-model="queryParams.dateDue"
          placeholder="请输入到期日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成立时间" prop="establishedTime">
        <el-date-picker clearable
          v-model="queryParams.establishedTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择成立时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="现阶段科研订货任务" prop="researchOrderTask">
        <el-input
          v-model="queryParams.researchOrderTask"
          placeholder="请输入现阶段科研订货任务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="序号" prop="sequenceNumber">
        <el-input
          v-model="queryParams.sequenceNumber"
          placeholder="请输入序号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:enterprise:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:enterprise:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:enterprise:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:enterprise:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="enterpriseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="单位姓名" align="center" prop="departmentName" />
      <el-table-column label="统一社会信用代码" align="center" prop="creditCodes" />
      <el-table-column label="监管JDS" align="center" prop="representativeOffice" />
      <el-table-column label="菜单" align="center" prop="menus" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="KJ主业务分公司地址" align="center" prop="forceMainAddress" />
      <el-table-column label="机要地址" align="center" prop="confidentialAddress" />
      <el-table-column label="属性" align="center" prop="properties" />
      <el-table-column label="所属管辖类别" align="center" prop="categoryOfJurisdiction" />
      <el-table-column label="上市情况" align="center" prop="listedSituation" />
      <el-table-column label="BM等级" align="center" prop="securityGrade" />
      <el-table-column label="BM等级证书编号" align="center" prop="securityCertificateNo" />
      <el-table-column label="承制资格" align="center" prop="grindersQualification" />
      <el-table-column label="承制资格证书编号" align="center" prop="grindersQualificationNo" />
      <el-table-column label="申办日期" align="center" prop="bidDate" />
      <el-table-column label="续申日期" align="center" prop="renewedDate" />
      <el-table-column label="到期日期" align="center" prop="dateDue" />
      <el-table-column label="成立时间" align="center" prop="establishedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.establishedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="企业简介" align="center" prop="enterpriseProfile" />
      <el-table-column label="现阶段科研订货任务" align="center" prop="researchOrderTask" />
      <el-table-column label="序号" align="center" prop="sequenceNumber" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="部门ID" align="center" prop="deptId" />
      <el-table-column label="详细地址" align="center" prop="detailedAddress" />
      <el-table-column label="经营范围" align="center" prop="businessNatures" />
      <el-table-column label="承制范围" align="center" prop="productionScope" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="备注1" align="center" prop="note1" />
      <el-table-column label="备注2" align="center" prop="note2" />
      <el-table-column label="备注3" align="center" prop="note3" />
      <el-table-column label="备注4" align="center" prop="note4" />
      <el-table-column label="备注5" align="center" prop="note5" />
      <el-table-column label="备注6" align="center" prop="note6" />
      <el-table-column label="备注7" align="center" prop="note7" />
      <el-table-column label="备注8" align="center" prop="note8" />
      <el-table-column label="备注9" align="center" prop="note9" />
      <el-table-column label="备注10" align="center" prop="note10" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:enterprise:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:enterprise:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改承制单位信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="单位姓名" prop="departmentName">
          <el-input v-model="form.departmentName" placeholder="请输入单位姓名" />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="creditCodes">
          <el-input v-model="form.creditCodes" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="监管JDS" prop="representativeOffice">
          <el-input v-model="form.representativeOffice" placeholder="请输入监管JDS" />
        </el-form-item>
        <el-form-item label="菜单" prop="menus">
          <el-input v-model="form.menus" placeholder="请输入菜单" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="KJ主业务分公司地址" prop="forceMainAddress">
          <el-input v-model="form.forceMainAddress" placeholder="请输入KJ主业务分公司地址" />
        </el-form-item>
        <el-form-item label="机要地址" prop="confidentialAddress">
          <el-input v-model="form.confidentialAddress" placeholder="请输入机要地址" />
        </el-form-item>
        <el-form-item label="属性" prop="properties">
          <el-input v-model="form.properties" placeholder="请输入属性" />
        </el-form-item>
        <el-form-item label="所属管辖类别" prop="categoryOfJurisdiction">
          <el-input v-model="form.categoryOfJurisdiction" placeholder="请输入所属管辖类别" />
        </el-form-item>
        <el-form-item label="上市情况" prop="listedSituation">
          <el-input v-model="form.listedSituation" placeholder="请输入上市情况" />
        </el-form-item>
        <el-form-item label="BM等级" prop="securityGrade">
          <el-input v-model="form.securityGrade" placeholder="请输入BM等级" />
        </el-form-item>
        <el-form-item label="BM等级证书编号" prop="securityCertificateNo">
          <el-input v-model="form.securityCertificateNo" placeholder="请输入BM等级证书编号" />
        </el-form-item>
        <el-form-item label="承制资格" prop="grindersQualification">
          <el-input v-model="form.grindersQualification" placeholder="请输入承制资格" />
        </el-form-item>
        <el-form-item label="承制资格证书编号" prop="grindersQualificationNo">
          <el-input v-model="form.grindersQualificationNo" placeholder="请输入承制资格证书编号" />
        </el-form-item>
        <el-form-item label="申办日期" prop="bidDate">
          <el-input v-model="form.bidDate" placeholder="请输入申办日期" />
        </el-form-item>
        <el-form-item label="续申日期" prop="renewedDate">
          <el-input v-model="form.renewedDate" placeholder="请输入续申日期" />
        </el-form-item>
        <el-form-item label="到期日期" prop="dateDue">
          <el-input v-model="form.dateDue" placeholder="请输入到期日期" />
        </el-form-item>
        <el-form-item label="成立时间" prop="establishedTime">
          <el-date-picker clearable
            v-model="form.establishedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择成立时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="企业简介">
          <file-upload v-model="form.enterpriseProfile"/>
        </el-form-item>
        <el-form-item label="现阶段科研订货任务" prop="researchOrderTask">
          <el-input v-model="form.researchOrderTask" placeholder="请输入现阶段科研订货任务" />
        </el-form-item>
        <el-form-item label="序号" prop="sequenceNumber">
          <el-input v-model="form.sequenceNumber" placeholder="请输入序号" />
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="详细地址" prop="detailedAddress">
          <el-input v-model="form.detailedAddress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="经营范围" prop="businessNatures">
          <el-input v-model="form.businessNatures" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="承制范围" prop="productionScope">
          <el-input v-model="form.productionScope" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注1" prop="note1">
          <el-input v-model="form.note1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注2" prop="note2">
          <el-input v-model="form.note2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注3" prop="note3">
          <el-input v-model="form.note3" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注4" prop="note4">
          <el-input v-model="form.note4" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注5" prop="note5">
          <el-input v-model="form.note5" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注6" prop="note6">
          <el-input v-model="form.note6" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注7" prop="note7">
          <el-input v-model="form.note7" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注8" prop="note8">
          <el-input v-model="form.note8" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注9" prop="note9">
          <el-input v-model="form.note9" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注10" prop="note10">
          <el-input v-model="form.note10" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEnterprise, getEnterprise, delEnterprise, addEnterprise, updateEnterprise } from "@/api/system/enterprise";

export default {
  name: "Enterprise",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 承制单位信息表格数据
      enterpriseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        departmentName: null,
        creditCodes: null,
        representativeOffice: null,
        menus: null,
        address: null,
        forceMainAddress: null,
        confidentialAddress: null,
        properties: null,
        categoryOfJurisdiction: null,
        listedSituation: null,
        securityGrade: null,
        securityCertificateNo: null,
        grindersQualification: null,
        grindersQualificationNo: null,
        bidDate: null,
        renewedDate: null,
        dateDue: null,
        establishedTime: null,
        enterpriseProfile: null,
        researchOrderTask: null,
        sequenceNumber: null,
        userId: null,
        deptId: null,
        detailedAddress: null,
        businessNatures: null,
        productionScope: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        note1: [
          { required: true, message: "备注1不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询承制单位信息列表 */
    getList() {
      this.loading = true;
      listEnterprise(this.queryParams).then(response => {
        this.enterpriseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        departmentName: null,
        creditCodes: null,
        representativeOffice: null,
        menus: null,
        address: null,
        forceMainAddress: null,
        confidentialAddress: null,
        properties: null,
        categoryOfJurisdiction: null,
        listedSituation: null,
        securityGrade: null,
        securityCertificateNo: null,
        grindersQualification: null,
        grindersQualificationNo: null,
        bidDate: null,
        renewedDate: null,
        dateDue: null,
        establishedTime: null,
        enterpriseProfile: null,
        researchOrderTask: null,
        sequenceNumber: null,
        userId: null,
        deptId: null,
        detailedAddress: null,
        businessNatures: null,
        productionScope: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加承制单位信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEnterprise(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改承制单位信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEnterprise(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEnterprise(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除承制单位信息编号为"' + ids + '"的数据项？').then(function() {
        return delEnterprise(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/enterprise/export', {
        ...this.queryParams
      }, `enterprise_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
